<?php 	include("head.php");
		include_once("paging_function.php");
?><script language="javascript">

function check()
{
	if(document.edit.selectlan.value=='')
	
		{
			alert("Please Select Language");
			
			return false;
		}
	if(document.edit.title.value=='')
	
		{
			alert("Please Enter Title");
			document.edit.title.focus();
			return false;
		}
	if(document.edit.description.value=='')
	
		{
			alert("Please Enter Description");
			document.edit.description.focus();
			return false;
		}

    if ( ( document.edit.status[0].checked == false )
   		 && ( document.edit.status[1].checked == false )
		 && ( document.edit.status[2].checked == false )
		 && ( document.edit.status[3].checked == false ) )
	
		{
			alert("Please Enter Status");
			return false;
		}

	return true;
}

</script>
<script>
function changeUrl(indexalpha)
{
var url='approve.php?index='+indexalpha;
window.location=url;
}

</script>
<?php
/////////////////////////////////PAGING /////////////////
 	if(isset($_GET['page']) && $_GET['page']!='')
		{
		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
$limit=$adminpagelimit;
/////////////////////////////////////////////////////////////////	
?>
<?php
$statustype=$_POST['selectstatus'];

////////////////////////////////////////////    Block_---- DELETE  ///////////
if(isset($_POST['Submit']))
{
	$del=$_POST['del'];
	$no=count($del);
	if($no>0)
	{
	for($i=0;$i<$no;$i++)
	{
	   mysql_query("DELETE FROM ".APPROVALFILTER."  WHERE filterId= '".$del[$i]."' ");	   
	}
	echo '<script>window.location="approve.php?dlt=1"</script>';
	}
	$block=$_POST['count_UPDATE'];
	if($_POST['count_UPDATE']>0)
	{
	for($no_up=0; $no_up<$block;$no_up++)
	{
	if(isset($_POST['block'.$no_up]))
	{
	 mysql_query("UPDATE ".APPROVALFILTER."  set status='N' WHERE filterId='".$_POST['block'.$no_up]."'");
	}else{
	 mysql_query("UPDATE ".APPROVALFILTER."  set status='Y' WHERE filterId='".$_POST['block_hid'.$no_up]."'");
	}
	}
	echo '<script>window.location="approve.php?page='.$_GET['page'].'&loop='.$_GET['loop'].'&start='.$_GET['start'].'&blk=1"</script>';
	}
}

?>
<?php 
//////////////////////////////////////// insert edit query====================//////////
if(isset($_REQUEST['submit1']))
{
	if($_REQUEST['action']=='create')
	{
		if($_POST['selectlan']=='ENG')
			{
			$insert_query=mysql_query("INSERT INTO `".APPROVALFILTER."` SET `title` ='".$_POST['title']."',`langId`='1',`description` = '".$_POST['description']."',`status`='".$_POST['status']."'");
						
			echo '<script> window.location="approve.php?inst=1"</script>';
			}
		elseif($_POST['selectlan']=='JAP')
			{
			$insert_query=mysql_query("INSERT INTO `".APPROVALFILTER."` SET `title` ='".$_POST['title']."',`langId`='2',`description` = '".$_POST['description']."',`status`='".$_POST['status']."'");
			
			
			echo '<script> window.location="approve.php?inst=1"</script>';
			}
	}
	if($_REQUEST['action']=='edit')
	{
//		if($_POST['selectlan']=='ENG')
//			{
			$UPDATE=mysql_query("UPDATE `".APPROVALFILTER."` SET `title` ='".$_POST['title']."',`langId`=".$_POST['selectlan'].",`description` = '".$_POST['description']."',`status`='".$_POST['status']."' WHERE `filterId` ='".$_REQUEST['filterId']."'") ;			
			
			echo '<script> window.location="approve.php?updt=1"</script>';
			//}
//		if($_POST['selectlan']=='JAP')
//			{
//			$UPDATE=mysql_query("UPDATE `".APPROVALFILTER."` SET `title` ='".$_POST['title']."',`langId`='2',`description` = '".$_POST['description']."',`status`='".$_POST['status']."' WHERE `filterId` ='".$_REQUEST['filterId']."'") ;			
//			
//			echo '<script> window.location="approve.php?updt=1"</script>';
//			}
	}
}
////////////////////////////////end////////////////////////////////////////////////////////
?>

<fieldset>
<legend class="LEGEND"> APPROVAL FILTER </legend>
 <table width="100%" border="0" cellspacing="0" cellpadding="3">
 <tr><td>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	
	<tr style="display:" id="editWin">
	
	<td colspan='2' id="ShowMsg">
	</td>
	</tr>
	<?php 
	if((isset($_GET['blk']) && $_GET['blk']==1) || (isset($_GET['dlt']) && $_GET['dlt']==1) || (isset($_GET['inst']) && $_GET['inst']==1) || (isset($_GET['updt']) && $_GET['updt']==1) )
	{
	?>
	<tr>
	
	<td colspan='2' style="color:#FF0000">
	<?php 
	if(isset($_GET['blk']) && $_GET['blk']==1)
	{
	echo $msg1="Value Blocked/Unblocked Successfully!!!";
	}
	if(isset($_GET['dlt']) && $_GET['dlt']==1)
	{
	echo $msg1="Value Deleted Successfully!!!";
	}
	if(isset($_GET['inst']) && $_GET['inst']==1)
	{
	echo $msg1="Value insert Successfully!!!";
	}
	if(isset($_GET['updt']) && $_GET['updt']==1)
	{
	echo $msg1="Value UPDATE Successfully!!!";
	}
	?></td>
	</tr>
	<?php
	}
	?>
	</table>



   <table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod">
	<?php
	if(isset($_REQUEST['action']))
	{
	$editquery=mysql_query("SELECT * FROM ".APPROVALFILTER." WHERE filterId='".$_REQUEST['filterId']."'");
	$fetch=mysql_fetch_array($editquery);
	?>
	<tr><td colspan="6" id="edit_section" style="display:;">
	<fieldset>
	<legend class="LEGEND"> <?php echo ucfirst($_REQUEST['action']);?>Filter</legend>
	<form name="edit" action="" method="POST" onSubmit="return check();"  >
	<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
		<tr>
			<td width="27%" align="left" id="admin_text">Choose Language</td>
			<td width="10%" align="left">::</td>
			<td width="81%" align="left">
					<?php
						/*if(isset( $_Tamplate_name) &&  $_Tamplate_name!= '')
						{
							$select_LAng="select `langId` from ".EMAILTEMPLATE."  where templateName='".$_Tamplate_name."'";
							$EXEsellang=mysql_query($select_LAng) or die("Selection Error Language :<br>".$select_LAng.'<br>'.mysql_error());;
							if(mysql_num_rows($EXEsellang) > 0)
							{
								$selectedResuld=mysql_fetch_assoc($EXEsellang);
								$selectedLang=$selectedResuld['langId'];
							}
							else
							{
								$selectedLang='';
							}
						}*/
						if($fetch['langId'] != '')
							$selectedLang=$fetch['langId'];
						else
							$selectedLang='';
							
						
						$selectlanguage="SELECT * FROM ".LANGUAGE." WHERE 1";
						$Exequery=mysql_query($selectlanguage) or die("Selection Error Language :<br>".$selectlanguage.'<br>'.mysql_error());
						if(mysql_num_rows($Exequery) > 0)
						{
					?>
					<select name="selectlan" id="selectlan">
						<option value="" <?php if($selectedLang == '') echo 'selected';?>>--Select one--</option>
					<?php
							while($resultExequery = mysql_fetch_assoc($Exequery))
							{
								if($resultExequery['langId'] == $selectedLang)
									$selected="selected";
								else
									$selected="";
					?>
						<option value="<?php echo $resultExequery['langId']?>" <?php echo $selected;?>><?php echo $resultExequery['langName']?></option>
					<?php
							}
					?>
					</select>
					<?php
						}
					?>
					
				
				
			
			
			
			
			
			
			<!--<select name="selectlan" class="SMALL" >
						<option value="" selected="selected">Choose Language</option>
						<option value="ENG"  <?php #if($fetch['langId'] == "1") echo 'selected'; ?>>ENGLISH</option>
						<option value="JAP"  <?php #if($fetch['langId'] == "2") echo 'selected'; ?>>JAPANEES</option>
						
					    </select> --> </td>

			
		</tr>
		<tr>
			<td width="27%" align="left" id="admin_text">Title </td>
			<td width="10%" align="left">::</td>
			<td width="81%" align="left"><input type="text" name="title" value="<?php echo $fetch['title'];?>" size="43"></td>
		</tr>
		<tr>
			<td width="27%" align="left" id="admin_text">Description</td>
			<td width="10%" align="left">::</td>
			<td width="81%" align="left"><textarea  name="description"  cols="40" rows="7"><?php  echo stripslashes($fetch['description']);?></textarea></td>
		</tr>
		<tr>
			<td width="27%" align="left" id="admin_text">Status</td>
			<td width="10%" align="left">::</td>
			<td width="81%" align="left" >Active
			<input type="radio" name="status" <?php if($fetch['status']=='Y'){?> checked="checked" <?php } ?> value="Y" >
			&nbsp;&nbsp;Inactive
			<input type="radio" name="status" <?php if($fetch['status']=='N'){?> checked="checked" <?php } ?> value="N" > &nbsp;&nbsp;Block
			<input type="radio" name="status" <?php if($fetch['status']=='B'){?> checked="checked" <?php } ?> value="B" ></td>
		</tr>
		<tr>
			<td align="center">&nbsp;</td>
			<td align="center">&nbsp;</td>
			<td align="left"><input type="submit" name="submit1" value="<?php if($_REQUEST['action']=='create'){echo insert;}else echo UPDATE;?>" />
				&nbsp;
				<input type="button" value="Close" name="close_frm" id="close_frm" onClick="window.location='approve.php'" /></td>
			</tr></table>
			</form>
			</fieldset>
			<?php } ?>
			</td>
		</tr>
		<tr>
		
			<td height="15" colspan="6" align="center" style="color:#000000;font-size:12px;"><p><strong style="font-weight: 400">Click on the alphabets to browse Filter Title &nbsp;</strong></p><?php include_once("search_alphabets.php");?></td>
		
		</tr>
	<form name="search" method="POST" >
		<tr>
			<td colspan="6">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr><td colspan="6" align="left" valign="middle"><font size="2" ><strong>
					<a href="approve.php?action=create"> Create Filter </a></strong></font>       </td></tr>
					<tr>
					<td class="SMALL">Search By
					<td class="SMALL"> Filter Title:
                      <input type="text" name="box" id="box" value="<?php echo $_REQUEST['box'] ;?>" />                    
					<td class="SMALL"> Description:
					<input type="text" name="desc" id="desc" value="<?php echo $_REQUEST['desc'] ;?>"  />					
					<td class="SMALL" > Approval Status:<select name="selectstatus" class="SMALL" >
										<option value="" selected="selected">Ad Status </option>
										<option value="Y"  <?php if($statustype == "Y") echo 'selected'; ?>>Active</option>
										<option value="N"  <?php if($statustype == "N") echo 'selected'; ?>>Inactive</option>
										<option value="B" <?php if($statustype == "B") echo 'selected'; ?>>Block</option>
										</select>					</td>
					<td  align="left" ><input type="submit" name="search" value="Search"></td>
					
					<td class="SMALL"><a href="approve.php" style="color:#000000;font-size:12px;">View All</a> </td>
					</tr>
			</table>
			</td>
		</tr>
	</form>
<?php	
	  $SELECTlanguage="SELECT * FROM ".LANGUAGE." WHERE 1";
	  $exeselang=mysql_query($SELECTlanguage) or die("Error in selection: <br>".$SELECTlanguage.'<br>'.mysql_error());
	  if(mysql_num_rows($exeselang) > 0)
	  {
	  	$CheckAvailavility=0;
	  	while($resultexeselang=mysql_fetch_assoc($exeselang))
		{
	?>
			<tr bgcolor="#C1D2EC">
			    <td height="32" align="left" valign="middle" colspan="4" style="font-size:14px; font-weight:bold;"><?php echo ucfirst($resultexeselang['langName']); ?>&nbsp;Approval Filter</td>
			    <td align="left" valign="middle">&nbsp;</td>
			    <td align="left" valign="middle">&nbsp;</td>
			</tr>
		      <!--<tr bgcolor="#6F8DBC">
		        <td width="7%" height="28" align="left" valign="middle"><font color="#FFFFFF"><strong>Id</strong></font></td>
		        <td colspan="2" align="left" valign="middle"><font color="#FFFFFF"><strong>TemplateName</strong></font></td>
		        <!--<td width="27%" align="left"><font color="#FFFFFF"><strong>Language</strong></font></td> 
		        <td width="31%" align="left" valign="middle"><font color="#FFFFFF"><strong>Edit</strong></font></td>
		        <td width="22%" align="left" valign="middle"><font color="#FFFFFF"><strong>Delete</strong></font></td>
		      </tr> -->
	

	
	
<?php
			$search="SELECT * FROM ".APPROVALFILTER ." WHERE 1 AND `langId`=".$resultexeselang['langId'];
			if(isset($_POST['selectstatus']) && $_POST['selectstatus']!="")
		
			{
				$param="selectstatus=".$_REQUEST['selectstatus'];
				$search= $search." AND status = '".$_REQUEST['selectstatus']."'";
		 
			}
			if($_REQUEST['box']!='' && isset($_REQUEST['box']))
			{
		
				$param="box=".$_REQUEST['box'];
				$search=$search." AND title like'".$_REQUEST['box']."%'";
				
			
			}
			if($_REQUEST['desc']!='' && isset($_REQUEST['desc']))
			{
		
				$param="desc=".$_REQUEST['desc'];
				$search=$search." AND description like'".$_REQUEST['desc']."%'";
				
			
			}
			elseif($_REQUEST['index']!='' && isset($_REQUEST['index']))
			{
		
				$param="index=".$_REQUEST['index'];
				$search=$search." AND title like'".$_REQUEST['index']."%'";
				
			
			}
			
			$search=$search." ORDER BY filterId  DESC limit $page,$limit";
			//echo $search;
			$searchquery=mysql_query($search) or die('error1'.mysql_error());
			
		
			if(mysql_num_rows($searchquery)>0)
			{
			
			?>
			<form name="form_admin_management" action="" method="post">
			
				<tr bgcolor="#6F8DBC">
					<td width="4%" height="28" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
					<td width="25%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Title </strong></td>
					<td width="49%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Description</strong></td>
					<!--      <td width="13%" align="center" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>-->
					<td width="8%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>
					<td width="7%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>
					<td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
				</tr>
			<?php 
			$count=0;
			$sno=1;
			$loop=0;
			while($searcharray=mysql_fetch_array($searchquery))
			{
			$loop++;
					if($loop == 1)
					$bgcolor = "#F0F0FF";
					else 
					$bgcolor = "#CCCCFF";
			?>
				<tr bgcolor="<?php echo $bgcolor; ?>">
					<td height="32" style="color:#000000;font-size:12px;"><strong><?php echo $sno+$_GET['page'];?></strong></td>
					<td align="center" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['title']); ?></td>
					<td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php $rest =$searcharray['description'];echo substr("$rest",0,50);?>
						</td>
					<td align="center" valign="middle"><a href="approve.php?action=edit&filterId=<?php echo $searcharray['filterId'];?>" ><img src="images/edit_icon.gif" border="0"/></a></td>
					<td align="center" valign="middle">
						<?php if($searcharray['status']=='B'){ echo Blocked;}
							elseif($searcharray['status']=='Y'){ echo Active;}
							elseif($searcharray['status']=='P'){ echo Pending;}
							elseif($searcharray['status']=='N'){ echo Inactive;}?>
					</td>
					<td align="center"><input type="checkbox" name="del[]" value="<?php echo $searcharray['filterId'];?>"></td>
				</tr>
			<?php 
			$count++;
			$sno++;
					if($loop == 2)
						{
						$loop = 0;
						}	
					}
					?>
				<tr>
					<td colspan="3">&nbsp;</td>
					<td colspan="3" align="right"><input type="hidden" name="count_UPDATE" value="<?php echo $count; ?>">
					<input type="submit" name="Submit" value="Update"></td>
				</tr>
				<tr>
					<td colspan="6" align="center" style="color:#FF0000"><?php echo paging($search,$page,$limit,'',$param);?></td>
				</tr>
			</form>
			<?php
			
			}
			
			else
			
			{
			
			?>
				<tr bgcolor="#6F8DBC">
					<td width="4%" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
					<td width="25%" align="center" style="color:#ffffff;font-size:12px;"><strong>Title </strong></td>
					<td style="color:#ffffff;font-size:12px;"><strong>Description</strong></td>
					<td width="8%" align="center" style="color:#ffffff;font-size:12px;"><strong>Edit</strong></td>
					<td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Block</strong></td>
					<td width="7%" align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
				</tr>
				<tr>
					<td colspan="6" align="center" height="96" class="DISPLAYMESSAGES">No filter available for <?php echo ucfirst($resultexeselang['langName']);?>!</td>
				</tr>
			<?php
			
			}
		}
	}
	else
	{
?>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td height="96" colspan="2" valign="middle" align="center" class="DISPLAYMESSAGES">No Records Available! </td>
			<td>&nbsp;</td>
		</tr>

<?php
	}
	?>
	</table>
  </td></tr></table>
</fieldset>
<?php 

include("foot.php");?>
